#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>//rand()
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;

int _,n,a[111111],b[111111];

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    cin >> _;
    while(_--){
        cin >> n;
        rep(i,1,n) cin >> a[i];
        rep(i,0,n) b[i] = 0;
        b[++b[0]] = a[1];
        rep(i,2,n){
            if(a[i] > a[i-1]){
                while(a[i+1] > a[i] && i < n) ++i; 
                b[++b[0]] = a[i];
                continue;
            } else {
                while(a[i+1] < a[i] && i < n) ++i;
                b[++b[0]] = a[i];
                continue;                
            }
        }
        cout << b[0] << "\n";
        rep(i,1,b[0]) cout << b[i] << " ";
        cout << "\n";
    }


    return 0;
}